﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using MyHotel.MyHotel_MHBaoCaoMatDo_BUS_Webservice;
using MyHotel.Reports;

namespace MyHotel
{
    public partial class frmBaoCaoMatDo : DevComponents.DotNetBar.Office2007Form
    {
        private List<BaoCaoMatDoReport> _listBaoCaoMatDo;

        public frmBaoCaoMatDo()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Bạn có muốn thoát không?", "Thoát", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            if (dr == DialogResult.Yes)
            {
                this.Close();
            }
        }

        private void frmBaoCaoMatDo_Load(object sender, EventArgs e)
        {
            cboThang.SelectedIndex = DateTime.Today.Month - 1;
        }

        private void cboThang_SelectedIndexChanged(object sender, EventArgs e)
        {
            BaoCaoMatDo[] bcmd;
            MHBaoCaoMatDoBUSWSSoapClient ws = new MHBaoCaoMatDoBUSWSSoapClient();
            bcmd = ws.getListByThang(cboThang.SelectedIndex + 1);

            _listBaoCaoMatDo = createListReport(bcmd);
            dgvBaoCaoMD.DataSource = _listBaoCaoMatDo;
        }

        private List<BaoCaoMatDoReport> createListReport(BaoCaoMatDo[] bcmd)
        {
            List<BaoCaoMatDoReport> list = new List<BaoCaoMatDoReport>();
            foreach (BaoCaoMatDo bc in bcmd)
            {
                BaoCaoMatDoReport bcReport = new BaoCaoMatDoReport();
                bcReport.SoNgayThue = bc.SoNgayThue;
                bcReport.TenPhong = bc.TenPhong;
                bcReport.TiLe = bc.TiLe;

                list.Add(bcReport);
            }

            return list;
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor; 
                int thang = Convert.ToInt32(cboThang.SelectedIndex) + 1;
                frmReportBaoCaoMatDo report = new frmReportBaoCaoMatDo(thang, _listBaoCaoMatDo);
                report.ShowDialog();  
                this.Cursor = Cursors.Default; 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        } 

        private void dgvBaoCaoMD_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            for (int i = 0; i < dgvBaoCaoMD.Rows.Count; i++)
                dgvBaoCaoMD.Rows[i].Cells[0].Value = i + 1;
        } 
    }

    public class BaoCaoMatDoReport
    {
        string _tenPhong;
        public string TenPhong
        {
            get { return _tenPhong; }
            set { _tenPhong = value; }
        }
        int _soNgayThue;
        public int SoNgayThue
        {
            get { return _soNgayThue; }
            set { _soNgayThue = value; }
        }
        double _tiLe;
        public double TiLe
        {
            get { return _tiLe; }
            set { _tiLe = value; }
        }
    }
}